package com.senpai.ikhtiar;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.R.integer;
import android.content.Context;
import android.widget.TextView;
import android.widget.Toast;
import dev.dworks.libs.awizard.model.PageList;
import dev.dworks.libs.awizard.model.WizardModel;
import dev.dworks.libs.awizard.model.page.BranchPage;
import dev.dworks.libs.awizard.model.page.CustomerInfoPage;
import dev.dworks.libs.awizard.model.page.MultipleFixedChoicePage;
import dev.dworks.libs.awizard.model.page.ReviewPage;
import dev.dworks.libs.awizard.model.page.SingleFixedChoicePage;

public class QuestionWizardModel extends WizardModel {
	
	int number_question = 0;
	String myJsonQuestion;
	InputStream is;
	String category;
	JSONObject jsonObj;
	JSONArray jsonArray;
	JSONObject jsonObjMain;

	public QuestionWizardModel(Context context) {
		super(context);
		// TODO Auto-generated constructor stub

	}

	@Override
	protected PageList onNewRootPageList() {
		//getQuestion();
		
		
		BranchPage branchPage = new BranchPage(this, "");
		branchPage.addBranch(
				"Sandwich",
				new SingleFixedChoicePage(this, "Bread").setChoices("White",
						"Wheat", "Rye", "Pretzel", "Ciabatta")
						.setRequired(true),

				new BranchPage(this, "Toasted?")
						.addBranch(
								"Yes",
								new SingleFixedChoicePage(this, "Toast time")
										.setChoices("30 seconds", "1 minute",
												"2 minutes")).addBranch("No")
						.setValue("No"));

		return new PageList(branchPage,
				new CustomerInfoPage(this, "Your info").setRequired(true),
				new ReviewPage(this, "Review"));

	}

	private void getQuestion() {

		StringBuffer sb = new StringBuffer();
		BufferedReader br = null;
		try {
			br = new BufferedReader(new InputStreamReader(is,(
					"QuestionsData.json")));
			String temp;
			while ((temp = br.readLine()) != null)
				sb.append(temp);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		myJsonQuestion = sb.toString();

		try {

			JSONObject jsonObjMain = new JSONObject(myJsonQuestion);

			JSONArray jsonArray = jsonObjMain.getJSONArray("Questions");

			JSONObject jsonObj = jsonArray.getJSONObject(number_question);

			int idQuestion = jsonObj.getInt("Id_Question");
			category = jsonObj.getString("Category_Question");
			String question = jsonObj.getString("Content_Question");

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
